package com.liao.common.exception;

import com.liao.common.constant.StatusCodeEnum;
import com.liao.common.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: ljt
 * @Description: 全局异常处理类
 * @DateTime: 2025/2/16 下午4:59
 **/
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

//    @ExceptionHandler(value = Exception.class)
//    public R handleException(Exception e){
//        log.error("全局异常处理类：{}",e);
//        return R.error(e.getMessage());
//    }

    @ResponseStatus(HttpStatus.OK)
    @ExceptionHandler(Exception.class)
    public Result<String> handle(Exception e) {
        log.error("全局异常信息：{}", e);
        return Result.error(StatusCodeEnum.STATUS500.getCode(), StatusCodeEnum.STATUS500.getMsg() + ":" + e.getMessage());
    }
}
